package server;

import java.io.*;
import java.net.Socket;
import java.net.UnknownHostException;
import java.sql.*;
import java.util.*;

import javax.swing.*;

import com.sun.rowset.CachedRowSetImpl;

public class Database {
	private Connection conn;
	private Statement stat;
	static ImageIcon iconax = new ImageIcon("Risorse/iconax.png");
	private boolean connesso = false;
	private Socket s;
	private ObjectOutputStream out = null;
	private ObjectInputStream in;
	private int codice;
	
	public Statement getStat(){
		return stat;
	}

	public Database() throws SQLException, IOException {
		conn = getConnection();
		stat = conn.createStatement();
	}

	public void chiudiConnessione() throws SQLException {
		conn.close();
	}

	public Connection getConnection() throws SQLException, IOException {
		Properties props = new Properties();
		FileInputStream in = new FileInputStream("Risorse/database.properties");
		props.load(in);
		in.close();
		String drivers = props.getProperty("jdbc.drivers");
		String url = props.getProperty("jdbc.url");
		String username = props.getProperty("jdbc.username");
		String password = props.getProperty("jdbc.password");
		if (drivers != null)
			System.setProperty("jdbc.drivers", drivers);
		return DriverManager.getConnection(url, username, password);
	}

}
